package slef.xchen;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;

/**
 * @author chenxing
 */
public class Counter {

	private static final Map<String, AtomicLong> counterContainer = new ConcurrentHashMap<>();

	public static synchronized Long incr(String key) {
		AtomicLong counter = counterContainer.get(key);
		if(null == counter) {
			counter = new AtomicLong();
			counterContainer.put(key, counter);
		}
		return counter.incrementAndGet();
	}

}
